﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using HandyControl.Controls;
using Microsoft.Extensions.DependencyInjection;
using QModels;
using QServices;
using QServices.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QControlCenter.ViewModel
{
    public partial class ParameterSettingViewModel: QBaseVM
    {

        [ObservableProperty]
        private string iD;

        [ObservableProperty]
        private string? region;

        /// <summary>
        /// 适宜温度
        /// </summary>
        [ObservableProperty]
        private decimal suitableTemperature;

        /// <summary>
        /// 报警温度
        /// </summary>
        [ObservableProperty]
        private decimal alarmTemperature;

        /// <summary>
        /// 降温模式启动温度
        /// </summary>
        [ObservableProperty]
        private decimal coolingTemperature;

        /// <summary>
        /// 保温温度启动温度
        /// </summary>
        [ObservableProperty]
        private decimal keepTemperature;

        /// <summary>
        /// 二氧化碳适宜浓度
        /// </summary>
        [ObservableProperty]
        private decimal suitableCo2;

        [ObservableProperty]
        private decimal gear_1_Temperature;
        [ObservableProperty]
        private decimal gear_2_Temperature;
        [ObservableProperty]
        private decimal gear_3_Temperature;
        [ObservableProperty]
        private decimal gear_4_Temperature;
        [ObservableProperty]
        private decimal gear_5_Temperature;
        [ObservableProperty]
        private decimal gear_6_Temperature;
        [ObservableProperty]
        private decimal gear_7_Temperature;
        [ObservableProperty]
        private decimal startTemperatureWaterPump;
        [ObservableProperty]
        private decimal? startTimeWaterPump;
        [ObservableProperty]
        private decimal? stopTimeWaterPump;

        [ObservableProperty]
        private decimal temperature_1_GuidePlate;
        [ObservableProperty]
        private decimal temperature_2_GuidePlate;
        [ObservableProperty]
        private decimal temperature_3_GuidePlate;

        public ParameterSettingViewModel()
        {
            
        }

        [RelayCommand]
        public void SaveParameterSetting()
        {
            var info = new DosingParameter();
            this.UpdateTo(info);
            AppRuntime.GetService().GetService<ParameterSettingService>().SaveParameterSetting(info);
			Growl.SuccessGlobal("保存成功!");
            AppRuntime.Logger_Info("保存参数设置成功");
		}


        public void InitData()
        {
            if (string.IsNullOrWhiteSpace(Region)) return;
            var info=AppRuntime.GetService().GetService<ParameterSettingService>().GetDosingParameter(Region);
            if (info != null)
            {
                this.UpdateFrom(info);
            }
        }

    }
}
